package com.zadetk.helpyou.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zadetk.helpyou.R;
import com.zadetk.helpyou.activities.PublishServiceActivity;

import java.util.ArrayList;
import java.util.HashMap;

public class GridViewAdapter extends BaseAdapter implements  View.OnClickListener{

    private Context mContext;
    private ArrayList<HashMap<String, Object>> mList;
    private LayoutInflater inflater;

    public GridViewAdapter(Context mContext, ArrayList<HashMap<String, Object>> mList) {
        this.mContext = mContext;
        this.mList = mList;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        if (mList == null)
            return 0;
        return this.mList.size();
    }

    @Override
    public Object getItem(int position) {
        if (mList == null)
            return null;
        return this.mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.layout_gridview, null);
            viewHolder.mTextView = (TextView) convertView.findViewById(R.id.textView_gridView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (mList != null) {
                viewHolder.mTextView.setText("测试");
                viewHolder.mTextView.setOnClickListener(this);
        }
        return convertView;
    }

    @Override
    public void onClick(View v) {
        mContext.startActivity(new Intent(mContext, PublishServiceActivity.class));
    }

    class ViewHolder {
        TextView mTextView;
    }

}












